import config from '@/config.ts'
import axios from 'axios'
import store from 'store'
export const reqExportFile = (url, data='', method = 'POST') =>{
    return new Promise((resolve, reject) => {
        axios({
            method: method,
            url: config.server + url,
            data: data,
            responseType: 'blob',
            headers: {
                'token': store.get('token')
            }
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
//导出excel
export const createExcel = (res, name) =>  {
    let blob = new Blob([res], {
        type: 'application/vnd.ms-excel'
    })
    let fileName = name + '.xlsx'
    // 允许用户在客户端上保存文件
    if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(blob, fileName)
    } else {
        var link = document.createElement('a')
        link.href = window.URL.createObjectURL(blob)
        link.download = fileName
        link.click()
        //释放内存
        window.URL.revokeObjectURL(link.href)
    }
}